import request from '@/utils/axios'

// 获取指定课程的学生列表
export function getStudentList(courseManageId) {
  if (!courseManageId) {
    throw new Error('courseManageId is required');
  }
  return request({
    url: `/course/student?courseManageId=${courseManageId}`,
    method: 'get'
  })
}

// 上传学生名单
export function uploadStudentList(formData) {
  return request({
    url: '/course/uploadStudent',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    // 添加上传进度处理
    onUploadProgress: progressEvent => {
      const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
      console.log('上传进度:', percentCompleted)
    }
  })
}

// 删除学生
export function deleteStudent(teamId) {
  return request({
    url: '/course/deStudent',
    method: 'delete',
    params: { teamId }
  });
}

// 获取课程详情
export function getCourseDetail(courseManageId) {
  return request({
    url: `/course/detail/${courseManageId}`,
    method: 'get'
  });
}

// 获取用户信息
export function getUserInfo(username) {
  return request({
    url: `/user/info`,
    method: 'get',
    params: { username }
  });
}

// 获取教师课程列表
export function getTeacherCourses(userId) {
  return request({
    url: '/course',
    method: 'get',
    params: { userId }
  });
}
